<?php
/**
 *
 * 版权所有：安德玛(underArmour)
 * 作    者：1554324405@qq.com
 * 日    期：2020-05-20
 * 版    本：1.0.0
 * 功能说明：资金监控控制器。
 *
 **/

namespace Admin\Controller;

class IncomeController extends ComController
{
    public function index()
    {
        $p = isset($_GET['p']) ? intval($_GET['p']) : '1';
        $type = I('get.type','','htmlspecialchars');
        $key = I('get.keyword','','htmlspecialchars');
        $m = M('user_income');
        
        if($type){
            $where['a.type'] = $type;
        }
        
        if($key){
            $where_bear['_logic'] = 'or';
            $where_bear['b.username'] = array('like','%'.$key.'%');
            $where_bear['b.nickname'] = array('like','%'.$key.'%');
            $where['_complex'] = $where_bear;
        }
        
        $pagesize =20;#每页数量
        $offset = $pagesize * ($p - 1);//计算记录偏移量
        $count = $m
                   ->alias("a")
                   ->join("left join ".C('DB_PREFIX')."user b on a.uid=b.id")
                   ->where($where)
                   ->count();
        $list = $m
                  ->alias("a")
                  ->join("left join ".C('DB_PREFIX')."user b on a.uid=b.id")
                  ->where($where)
                  ->field('a.*,b.username,b.nickname')
                  ->order('t desc')
                  ->where($where)
                  ->limit($offset . ',' . $pagesize)
                  ->select();
        $page = new \Think\Page($count, $pagesize);
        $page = $page->show();
        $this->assign('list', $list);
        $this->assign('page', $page);
        $this->assign('type',$type);
        $this->assign('p',$p);
        $this->display();
    }
}